package login;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import meu.Gui;
import meu.ImagePanel;

public class Menu {

	private final JFrame janela;

	public Menu() {
		janela = new JFrame("Menu");
		JPanel painel = new JPanel();
		janela.getContentPane().add(painel);
		painel.setLayout(new BorderLayout());
		ImagePanel image = new ImagePanel(new ImageIcon(
				"./Imagens/Fundo_Inicial.jpg").getImage());
		painel.add(image);
		JPanel painelBotoes = new JPanel();
		painelBotoes.setLayout(new GridLayout(3, 1));
		JButton start = new JButton("Iniciar");
		JButton highscores = new JButton("Highscores");
		JButton exit = new JButton("Sair");
		painelBotoes.add(start);
		painelBotoes.add(highscores);
		painelBotoes.add(exit);
		painel.add(painelBotoes, BorderLayout.SOUTH);
		start.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				janela.setVisible(false);
				new Gui();
			}
		});
		highscores.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				new Highscores(400, 100);
			}
		});
		exit.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				int x = JOptionPane.showConfirmDialog(janela,
						"Quer mesmo sair?");
				if (x == 0) {
					System.exit(0);
				}
			}
		});
		janela.addWindowListener(new WindowListener() {
			public void windowOpened(WindowEvent arg0) {
			}

			public void windowIconified(WindowEvent arg0) {
			}

			public void windowDeiconified(WindowEvent arg0) {
			}

			public void windowDeactivated(WindowEvent arg0) {
			}

			public void windowClosing(WindowEvent arg0) {
				int x = JOptionPane.showConfirmDialog(janela,
						"Quer mesmo sair?");
				if (x == 0)
					System.exit(0);
			}

			public void windowClosed(WindowEvent arg0) {
				System.exit(0);
			}

			public void windowActivated(WindowEvent arg0) {
			}
		});

		janela.setLocation(100, 100);
		janela.setResizable(false);
		janela.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		janela.setSize(300, 350);
		janela.setVisible(true);
	}

	public static void main(String[] args) {
		new Menu();
	}
}